package com.example.myapplication.acticity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

import com.example.myapplication.PlayService;
import com.example.myapplication.R;
import com.example.myapplication.fagment.InternetMusicFragment;
import com.example.myapplication.fagment.LocalMusicFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class HomeActivity extends BaseActivity {

    private LocalMusicFragment localMusicFragment1;
    private InternetMusicFragment internetMusicFragment;
    private BottomNavigationView bottomNavigationView;
    private NavController navController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        initView();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbindPlaySerevce();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();


        onDestroy();
    }

    @Override
    public void publish(int progress) {

    }
    @Override
    public void change(int position) {
//        if (navController.getCurrentDestination().getId() == R.id.localMusicFragment) {
//            localMusicFragment1 = new LocalMusicFragment();
//            localMusicFragment1.changeUiStatus(position);
//        } else if (navController.getCurrentDestination().getId() == R.id.internetMusicFragment) {
//            //internetMusicFragment.changeUiStatus(position);
//        }
    }

//    /**
//     * 切换播放位置
//     * 判断是在那个fragment操作调用哪个fragment的方法
//     * @param position
//     */
//    @Override
//    public void change(int position) {
//        if (navController.getCurrentDestination().getId() == R.id.localMusicFragment){
//            localMusicFragment1 = new LocalMusicFragment();
//            localMusicFragment1.changeUiStatus(position);
//        }else if (navController.getCurrentDestination().getId() == R.id.internetMusicFragment){
//            internetMusicFragment.changeUiStatus(position);
//        }
//    }

    private void initView() {
        bottomNavigationView = findViewById(R.id.bnv);
        navController = Navigation.findNavController(this,R.id.fragment);
//        AppBarConfiguration configuration = new AppBarConfiguration.Builder(bottomNavigationView.getMenu()).build();
//        NavigationUI.setupActionBarWithNavController(this,navController,configuration);
        NavigationUI.setupWithNavController(bottomNavigationView, navController);
    }
}
